package com.google.code.chaotic.ejb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Map;

import javax.persistence.EntityManagerFactory;

public class EjbUtils {

	public static Connection getConnection(EntityManagerFactory emf)
			throws ClassNotFoundException, SQLException {
	
		Map<String, Object> props = emf.getProperties();
		Object driver = props.get("javax.persistence.jdbc.driver");
		Object url = props.get("javax.persistence.jdbc.url").toString();
		Object user = props.get("javax.persistence.jdbc.user");
		Object password = props.get("javax.persistence.jdbc.password");
	
		Class.forName(driver.toString());
		Connection conn = DriverManager.getConnection(url.toString(), user
				.toString(), password.toString());
		return conn;
	}

}
